package com.ruoyi.crm.sale.controller;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.sale.domain.CrmTeam;
import com.ruoyi.crm.sale.service.ICrmTeamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 团队，针对客户或商机进行服务Controller
 * 
 * @author ruoyi
 * @date 2021-09-08
 */
@RestController
@RequestMapping("/crm/team")
public class CrmTeamController extends BaseController
{
    @Autowired
    private ICrmTeamService crmTeamService;

    /**
     * 查询团队，针对客户或商机进行服务列表
     */
    @PreAuthorize("@ss.hasPermi('crm:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmTeam crmTeam)
    {
        startPage();
        List<CrmTeam> list = crmTeamService.selectCrmTeamList(crmTeam);
        return getDataTable(list);
    }
    /**
     * 查询团队，针对客户或商机进行服务列表
     */
    @PreAuthorize("@ss.hasPermi('crm:team:list')")
    @GetMapping("/listNoPage")
    public TableDataInfo listNoPage(CrmTeam crmTeam)
    {
        List<CrmTeam> list = crmTeamService.selectCrmTeamList(crmTeam);
        return getDataTable(list);
    }

    /**
     * 导出团队，针对客户或商机进行服务列表
     */
    @PreAuthorize("@ss.hasPermi('crm:team:export')")
    @Log(title = "团队，针对客户或商机进行服务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmTeam crmTeam)
    {
        List<CrmTeam> list = crmTeamService.selectCrmTeamList(crmTeam);
        ExcelUtil<CrmTeam> util = new ExcelUtil<CrmTeam>(CrmTeam.class);
        return util.exportExcel(list, "团队，针对客户或商机进行服务数据");
    }

    /**
     * 获取团队，针对客户或商机进行服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:team:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmTeamService.selectCrmTeamById(id));
    }

    /**
     * 新增团队，针对客户或商机进行服务
     */
    @PreAuthorize("@ss.hasPermi('crm:team:add')")
    @Log(title = "团队，针对客户或商机进行服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmTeam crmTeam)
    {
        return toAjax(crmTeamService.insertCrmTeam(crmTeam));
    }

    /**
     * 修改团队，针对客户或商机进行服务
     */
    @PreAuthorize("@ss.hasPermi('crm:team:edit')")
    @Log(title = "团队，针对客户或商机进行服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmTeam crmTeam)
    {
        return toAjax(crmTeamService.updateCrmTeam(crmTeam));
    }

    /**
     * 删除团队，针对客户或商机进行服务
     */
    @PreAuthorize("@ss.hasPermi('crm:team:remove')")
    @Log(title = "团队，针对客户或商机进行服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmTeamService.deleteCrmTeamByIds(ids));
    }

    /**
     * 查询不在当前团队的所有人员
     */
    @PreAuthorize("@ss.hasPermi('crm:team:list')")
    @GetMapping("/getNotTeamUser")
    public List<Map<String, Object>> getNotTeamUser(CrmTeam crmTeam)
    {
        List<Map<String, Object>> list = crmTeamService.getNotTeamUser(crmTeam);
        
        return list;
    }
}
